<div class="layui-card-header">
	<h2 class="header-title">修改密码</h2>
</div>
<div class="layui-card-body" style="padding: 30px;">
	<form class="layui-form" id="form-psw">
		<div class="layui-form-item">
			<input type="password" name="oldPsw" required lay-verify="required" class="layui-input" placeholder="请输入原密码" lay-verType="tips">
		</div>
		<div class="layui-form-item">
			<input type="password" name="newPsw" required lay-verify="required|pwd" class="layui-input" placeholder="请输入新密码" lay-verType="tips">
		</div>
		<div class="layui-form-item">
			<input type="password" name="rePsw" required lay-verify="required|repsw" class="layui-input" placeholder="再次输入新密码" lay-verType="tips">
		</div>
		<div class="layui-form-item">
			<button class="layui-btn layui-btn-fluid" lay-submit lay-filter="submit-psw">确认修改</button>
		</div>
	</form>
</div>

<script>
	layui.use(['form', 'admin', 'layer'], function() {
		var form = layui.form;
		var admin = layui.admin;
		var layer = layui.layer;

		//监听提交
		form.on('submit(submit-psw)', function(data) {
			$.ajax({
				type: "POST",
				url: updatePwd,
				data: {
					pswd: data.field.oldPsw,
					newPswd: data.field.rePsw
				},
				dataType: "json",
				xhrFields: {
					withCredentials: true
				},
				success: function(data) {
					if(data.code == 0) {
						admin.closePopupRight();
						layer.msg(data.msg, {
							icon: 1
						})
					} else {
						layer.msg(data.msg, {
							icon: 2
						})
					}

				},
				error: function(result) {
					config.removeToken();
				},
			});
			return false;
		});

		//添加表单验证方法
		form.verify({
			pwd: [/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,15}$/, '密码必须包含大小写字母和数字的组合，可以使用特殊字符，长度在6-15之间'],
			repsw: function(t) {
				if(t !== $('#form-psw input[name=newPsw]').val()) {
					return '两次密码输入不一致';
				}
			}
		});
	});
</script>